@echo off

::boot bin 文件名
set boot=bin1.bin

::flash bin文件名
set flash=bin2.bin

::APP bin文件名
set app=bin3.bin



::boot偏移地址
set /a boot_offset=0x400

::app偏移地址
set /a app_offset=0x4400

::合成的文件名1
set creat_app=ALL_APP.bin 

::合成的文件名2
set new_app=APP.bin 

set emptyfile=emptyfile.bin 



set fileSize=0
 
for /F %%A in ('dir /-C "%boot%" ^| findstr /R /C:"^%boot%.*"') do (
    set fileSize=%%~zA
)
 
echo file size :%fileSize%




for %%a in (%boot%) do set /a FLASH_OFFSET_SIZE=%boot_offset%-%%~za
::以下部分不需要改
del %creat_app%
fsutil  file createnew %emptyfile% %FLASH_OFFSET_SIZE%  

type  %boot% >> %creat_app%
type  %emptyfile% >> %creat_app%
type  %flash% >> %creat_app% 

for %%a in (%creat_app%) do set /a OFFSET_SIZE=%app_offset%-%%~za
del %emptyfile%
fsutil  file createnew %emptyfile% %OFFSET_SIZE%  

type  %creat_app% >> %new_app%
type  %emptyfile% >> %new_app%
type  %app% >> %new_app% 

del %emptyfile%
del %creat_app%
